<p id="searchresults">
<?php

		if(isset($_POST['queryString'])) {
			$queryString = mysql_real_escape_string($_POST['queryString']);
			
			// Is the string length greater than 0?
			if(strlen($queryString) >0) {
				$query = mysql_query("SELECT * FROM subject  WHERE subject LIKE '%" . $queryString . "%' ORDER BY id LIMIT 4") or die(mysql_error());
				
				if($query) {
					// While there are results loop through them - fetching an Object.
					
					// Store the category id
					$subject_id = 0;
					while ($result = mysql_fetch_array($query)) {
						if($result['id'] != $subject_id) { // check if the category changed
							echo '<span class="category">'.$result['subject'].'</span>';
							$catid = $result['id'];
						}
	         			    $thumbnail = $this->PhpThumb->generate(
                                            array(
                                            'save_path' => WWW_ROOT . 'img/uploads/Subjects/thumbs',
                                            'display_path' => 'uploads/Subjects/thumbs',
                                            'error_image_path' => 'error.png',
                                            'src' => WWW_ROOT . "img/uploads/Subjects/".$result['image'],
                                            'w' => 46,
                                            'h' => 46,
                                            'q' => 100,
                                            'zc' => 1
                                            )
                                        );
                                       
                                           ?>
                                           
                                        <a href="<?php echo $this->base.'/Subjects/subject/'.$result['id']; ?>"><img src="<?php echo $this->base . '/img/'.$thumbnail['src']; ?>" class="lastest_img" width="<?php echo $thumbnail['w']; ?>" height="<?php echo $thumbnail['h']; ?>" title="<?php echo $result['subject']; ?>"/>
                                        <?php
                                       // echo $this->Html->link($this->Html->image($thumbnail['src'], array('class' => 'latest_img','width' => $thumbnail['w'], 'height' => $thumbnail['h'], 'title' => $result['subject'], 'alt' => $result['subject'])),array('controller'=>'Subjects','action'=>'subject',$result['id']),array('escape'=>false));
                                       			
	         			$description = $result['desc'];
	         			if(strlen($description) > 100) { 
	         				$description = substr($description, 0, 100) . "...";
	         			}
	         			
	         			echo '<span>'.$description.'</span></a>';
	         		}
	         		echo '<span class="seperator"><a href="#" title="Sitemap">Click To See More Result</a></span><br class="break" />';
				} else {
					echo 'ERROR: There was a problem with the query.';
				}
			} else {
				// Dont do anything.
			} // There is a queryString.
		} else {
			echo 'There should be no direct access to this script!';
		
                }
	
?>
</p>